package com.tan.api.controller.user;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tan.common.dto.user.RoleCreateDto;
import com.tan.common.dto.user.RoleMenuDTO;
import com.tan.common.dto.user.RoleUpdateDto;
import com.tan.common.query.user.RoleQuery;
import com.tan.common.vo.user.RoleVO;
import com.tan.core.response.ApiResponse;
import com.tan.user.service.ISysRoleService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author Tan
 * @since 2025-01-27
 */
@RestController
@RequestMapping("/sys/role")
public class SysRoleController {

    @Resource
    private ISysRoleService roleService;


    @GetMapping("/pages")
    public ApiResponse<IPage<RoleVO>> rolePages(RoleQuery roleQuery) {
        return ApiResponse.success(roleService.rolePages(roleQuery));
    }

    @PostMapping("/create")
    public ApiResponse<Void> createRole(RoleCreateDto roleCreateDto) {
        roleService.createRole(roleCreateDto);
        return ApiResponse.success();
    }

    @PostMapping("/update")
    public ApiResponse<Void> updateRole(RoleUpdateDto updateDto) {
        roleService.updateRole(updateDto);
        return ApiResponse.success();
    }

    @PostMapping("/del/{roleId}")
    public ApiResponse<Void> delRole(@PathVariable("roleId") Long roleId) {
        roleService.delRole(roleId);
        return ApiResponse.success();
    }


    @GetMapping("/roles")
    public ApiResponse<List<RoleVO>> getRoles() {
        return ApiResponse.success(roleService.roles());
    }


    @PostMapping("/allocation-menu")
    public ApiResponse<Void> allocationMenu(@RequestBody RoleMenuDTO roleMenuDTO) {
        roleService.allocationMenu(roleMenuDTO);
        return ApiResponse.success();
    }
}
